import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class GradientButton extends StatelessWidget {
  final String text;
  final TextStyle? textStyle;
  final IconData? icon;
  final VoidCallback? onPressed;
  final List<Color> gradientColors;
  final Color textColor;
  final double borderRadius;
  final double width;
  final double height;
  final bool showShadow;
  final bool enabled;

  const GradientButton({
    super.key,
    required this.text,
    this.textStyle,
    this.onPressed,
    this.icon,
    this.gradientColors = const [Color(0xFF9470FF), Color(0xFF6652F9)],
    this.textColor = Colors.white,
    this.borderRadius = 12,
    this.width = double.infinity,
    this.height = 48,
    this.showShadow = false,
    this.enabled = true,
  });

  @override
  Widget build(BuildContext context) {
    final effectiveColors = enabled
        ? gradientColors
        : gradientColors
              .map((c) => c.withAlpha((c.alpha * 0.3).toInt()))
              .toList();

    final effectiveTextColor = enabled ? textColor : textColor.withOpacity(0.3);

    return InkWell(
      borderRadius: BorderRadius.circular(borderRadius.r),
      onTap: enabled ? onPressed : null,
      child: Container(
        width: width.w,
        height: height.h,
        decoration: BoxDecoration(
          gradient: LinearGradient(
            colors: effectiveColors,
            begin: Alignment.centerLeft,
            end: Alignment.centerRight,
          ),
          borderRadius: BorderRadius.circular(borderRadius.r),
          boxShadow: showShadow && enabled
              ? [
                  BoxShadow(
                    color: gradientColors.last.withOpacity(0.3),
                    blurRadius: 8,
                    offset: const Offset(0, 4),
                  ),
                ]
              : null,
        ),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            if (icon != null) ...[
              Icon(icon, size: 20, color: effectiveTextColor),
              SizedBox(width: 8.w),
            ],
            Text(
              text,
              style:
                  textStyle ??
                  TextStyle(
                    color: effectiveTextColor,
                    fontSize: 14,
                    fontWeight: FontWeight.bold,
                  ),
            ),
          ],
        ),
      ),
    );
  }
}
